import time
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait  # 强制等待的方法
from selenium.webdriver.support import expected_conditions as EC   # 如果找不到则抛出异常
# 实例化驱动
driver = webdriver.Chrome()
# 打开网页
driver.get("http://www.bjhospital.net/")
# 全屏化
driver.maximize_window()
# 设置隐式等待
driver.implicitly_wait(15)
time.sleep(2)
# 搜索骨科
driver.find_element(By.NAME,"q").send_keys("骨科")
time.sleep(2)
# 搜索骨科
driver.find_element(By.XPATH,"//*[@id='header']/div/div/div/form/button").click()
time.sleep(2)
# 点击开打的第一个链接
driver.find_element(By.XPATH,"//*[text()='毕节市第一人民医院高值医用耗材网上阳光平台议价意向公开']").click()
time.sleep(5)
# 切换句柄
win = driver.window_handles  # 先获取所有的句柄
driver.switch_to.window(win[-1])  # 访问最后一个打开的句柄
time.sleep(5)
text = driver.find_element(By.XPATH,"/html/body/div[2]/div/div/a[3]").text
assert text =="最新公告"
time.sleep(5)